$(document).ready(function () {
  
   // --- saat radio opsi SEMUA terchecked
   $('#FooAssignModeAll').click(function() {
      $('#FooKaryawanId').html('');
      $('#FooDivisiId option:eq(0)').attr('selected', 'selected');
      $('#karyawan_list').hide('slow');
   });
   
   // --- saat radio opsi BEBERAPA terchecked
   $('#FooAssignModeSome').click(function() {
      $('#pilih_karyawan_fieldset').show();
      $('#pilih_karyawan_legend').show();
      $('#FooKaryawanId').show();
      
      $('#karyawan_list').show('slow');
   });
   
   $('#FooDivisiId').change(function() {
      var selected = $('#FooDivisiId :selected');
      var radioBtnSomeModeObj = $('#FooAssignModeSome');
      
      if (radioBtnSomeModeObj.attr('checked')) {
         
         $.ajax({
            type: 'get',
            url: app_root_path+'absensi_ajax/getKaryawanByDivisi',
            dataType: 'json',
            data: {'divisi_id':selected.val()},
            cache: 'false',
            success: function (data) {
               var selectContent = [];
               
               for (var i=0; i<data.length; i++) {
                  selectContent.push('<option value="'+data[i].Karyawan.id+'">'+data[i].Karyawan.nama+'</option>');
               }
               
               $('#FooKaryawanId').html(selectContent.join('')).fadeOut().fadeIn();
            }
         }
         );
         
      }
      
   });
}
);